<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>初始页面</title>
    <style>
        a {
            display: block;
            margin-top: 10px;
        }
        .input {
            box-sizing: border-box;
            width: 100%;
            height: 40px;
            border: 1px solid black;
            font-size: 14px;
        }
    </style>
</head>
<body>
    <input id="openid" class="input" type="text" value="odH4Hj7biIAs-Li7nyOgkLGcp48g">
    <a class="button1" href="javascript:void(0);" data-url="login.html">手机号登录</a>
    <a class="button2" href="javascript:void(0);" data-url="bindNo.html">资金账号绑定</a>
    <a class="button3" href="javascript:void(0);" data-url="loginNo.html">资金账号验证</a>

    <script>
        function setCookie(key, val, time) {
            var date = new Date(); //获取当前时间
            if (time == '' || time == undefined || time == null) { //time为空
                var exdate = new Date();
                exdate.setDate(exdate.getDate() + 365);
                document.cookie = key + "=" + val + "; path=/"; //设置cookie
            } else { //设置cookie留存时间
                var expiresDays = time; //将date设置为n天以后的时间
                date.setTime(date.getTime() + expiresDays * 24 * 3600 * 1000); //格式化为cookie识别的时间
                document.cookie = key + "=" + val + ";expires=" + date.toGMTString() + ";path=/";
            }
        }

        let but1 = document.querySelector(".button1")
        // 使用addEventListener
        but1.addEventListener("click",function(e){
            setCookie('openid', document.getElementById('openid').value)
            console.log(e.target.dataset.url)
            window.location.href = e.target.dataset.url
        })
        let but2 = document.querySelector(".button2")
        // 使用addEventListener
        but2.addEventListener("click",function(e){
            setCookie('openid', document.getElementById('openid').value)
            console.log(e.target.dataset.url)
            window.location.href = e.target.dataset.url
        })
        let but3 = document.querySelector(".button3")
        // 使用addEventListener
        but3.addEventListener("click",function(e){
            setCookie('openid', document.getElementById('openid').value)
            console.log(e.target.dataset.url)
            window.location.href = e.target.dataset.url
        })
    </script>
</body>
</html>